<script setup lang="ts">
import InfoFormFiled from '@/pages/System/Info/components/product/InfoFormFiled.vue';
import { getProductInfo } from '../../service/system.service';
import { ref } from 'vue';
import useStore from '@/stores';
import { ISystemInfo } from '../../product.datatype';
import { getProductData, getOSData, getDigitalWarrantyData } from '../../utils/system.util';
import { getStoreData, loading } from '@/utils/composition';

loading(true);
const systemInfoArray = ref([] as ISystemInfo[]);
const store = useStore();
const boardName = getStoreData('glob', 'boardName');
// 多系统裁剪
const multihost = getStoreData('loct', 'multihost');


getProductInfo()
  .then((res: any) => {
    const systemData = res.data;
    // 产品信息
    if (systemData.Product) {
      systemInfoArray.value.push(getProductData(systemData.Product, store));
    }
    // 软件信息
    if (!multihost) {
      if (systemData.OS && systemData.OS.iBMARunningStatus === 'Running') {
        systemInfoArray.value.push(getOSData(systemData.OS));
      } else {
        systemInfoArray.value.push({
          title: 'INFO_SYSTEM',
          backgroundClassName: 'os-img',
          id: 'systemInfo',
          data: [],
        });
      }
    }

    // 电子保单,服务年限不是有效值时隐藏“电子保单”标签
    if (
      systemData.DigitalWarranty &&
      systemData.DigitalWarranty.Lifespan !== null &&
      systemData.DigitalWarranty.Lifespan !== undefined
    ) {
      systemInfoArray.value.push(getDigitalWarrantyData(systemData.DigitalWarranty, store));
    }
    loading(false);
  })
  .catch(() => {
    loading(false);
  });
</script>

<template>
  <div id="infoProduct">
    <InfoFormFiled v-for="item in systemInfoArray" :key="item.title" :data="item" />
  </div>
</template>

<style lang="scss" scoped></style>
